#include "adddocument.h"

AddDocument::AddDocument(QString last_dir_)
{
setupUi(this);

doc_file = QLatin1String("");

last_dir = QLatin1String("");
    if ( true != last_dir_.isEmpty() )
    {
    last_dir = last_dir_;
    }

QPushButton * okButton = qobject_cast<QPushButton *>( buttonBox->button( QDialogButtonBox::Ok ) );
    if (okButton != NULL)
    {
    okButton->setDisabled(true);
    }

QObject::connect( docFileToolButton,
                  SIGNAL( clicked() ),
                  this,
                  SLOT( file_name() ) );
}

AddDocument::~AddDocument()
{
}

void AddDocument::file_name()
{
QString path = QFileDialog::getOpenFileName( this,
                                             tr("Select document"),
                                             last_dir );

doc_path = QDir::toNativeSeparators(path);                                   
doc_file = doc_path.section( QDir::separator(), -1);
last_dir = doc_path.section( QDir::separator(), 0, -2 );

fLineEdit->setText(doc_path);
    if ( true != doc_path.isEmpty() )
    {
    QPushButton * okButton = qobject_cast<QPushButton *>( buttonBox->button( QDialogButtonBox::Ok ) );
        if (okButton != NULL)
        {
        okButton->setEnabled(true);
        }
    }
}

QMap<QString, QString> AddDocument::return_selection()
{
QMap<QString, QString> m;
m["file_path"] = doc_path;
    if ( true == doc_path.isEmpty() )
    {
    QMessageBox::warning( this,
                          tr("Error"),
                          tr("Invalid path.") );      
    }

m["file_name"] = doc_file;
    if ( true == doc_file.isEmpty() )
    {
    QMessageBox::warning( this,
                          tr("Warning"),
                          tr("Empty file name.") );
    }

    if ( docSaveAsComboBox->currentText() == QString( QLatin1String("BLOB") ) )
    {
    m["file_type"] = QString( QLatin1String("BLOB") );
    }
    else if ( docSaveAsComboBox->currentText() == QString( QLatin1String("LINK") ) )
    {
    m["file_type"] = QString (QLatin1String("LINK") );
    }
    else
    {
    }

m["last_doc_dir"] = last_dir;

return m;    
}

